package educationaladministrationsystem.CSM.Mapper.Service.StudentAndTeacher.Certification;

import educationaladministrationsystem.CSM.Mapper.Service.ServiceInterface.StudentAndTeacherInterface.Certification.Certification;
import educationaladministrationsystem.Class.MajorProgram;
import educationaladministrationsystem.Class.Student;
import educationaladministrationsystem.Class.Teacher;
import educationaladministrationsystem.CSM.Mapper.StudentAndTeacher.Certification.CertificationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class CertificationService implements Certification {
    @Autowired
    CertificationMapper certificationMapper;

    @Override
    public List<MajorProgram> getAllProfessionMajor() {
        return certificationMapper.getAllProfessionMajor();
    }

    @Override
    public String getFacultiesIdByMajorProgramId(String id) {
        return certificationMapper.getFacultiesIdByMajorProgramId(id);
    }

    @Override
    public String getMajorNum(String id) {
        String result = String.valueOf(certificationMapper.getMajorNums(id) + 1);
        result = result.length() == 1 ? "00" + result : "0" + result;
        return result;
    }

    @Override
    public void uploadStudentCertification(Student student) {
        student.setEnrollmentDate(LocalDate.now().toString());
        certificationMapper.uploadStudentCertification(student);
    }

    @Override
    public String getTeacherNum() {
        String result = String.valueOf(certificationMapper.getTeacherNum() + 1);
        result = result.length() == 1 ? "00" + result : "0" + result;
        return result;
    }

    @Override
    public void uploadTeacherCertification(Teacher teacher) {
        teacher.setEmploymentDate(LocalDate.now().toString());
        certificationMapper.uploadTeacherCertification(teacher);
    }
}
